Rulebase Resolver - Sample Code (DerbyRulebaseService)

Rulebase Resolver - Sample Code (DerbyRulebaseService)

The most common implementations of Rulebase Resolver Plugins are for:

 

The Rulebase Resolver Plugin in this example:

Setup

The sample code that follows needs the following to run:

 

To setup this scenario:

  1. Create the SQL Database. It doesn't have to be DERBY, but that is what the source code is set up for. For the database schema, see below.
  2. Create the Rulebase in Oracle Policy Modeling, and run Build.
  3. Make sure that DERBY is running in network server mode.
  4. Upload the rulebase.zip from the rulebase output folder by using the java program 'BlobInsert <rulebase output folder>'. You can upload other rulebases if you want by running the program several times.
  5. Copy the code for the DerbyRulebaseService plugin (you may need to modify the database connection details).
  6. Compile and JAR the DerbyRulebaseService (you may need class files for your specific database implementation).
  7. Install the JAR file in Web Determinations. For more information, refer to Create a Plugin.
  8. Copy the DERBY library files to the library directory of your deployment (for example, <webroot>\WEB-INF\lib).
  9. Run a Web Determinations Interview.

Database Schema

There are two tables in the database, one called "RULEBASE" which stores all the available rulebases, with the following columns:

Name Type Description
ID VARCHAR(255) (Primary Key) Corresponds to the rulebase's unique identifier
CONTENT BLOB (2M) The rulebase archive

Derby Create Table Command:

create table RULEBASE(ID VARCHAR(255) not null primary key, CONTENT BLOB(2M));

 

The second table called "MODULE" stores the available modules, with the following columns:

Name Type Description
ID VARCHAR(255) (Primary Key) Corresponds to the module's unique name
CONTENT BLOB (2M) The module archive

Derby Create Table Command:

create table MODULE(NAME VARCHAR(255) not null primary key, CONTENT BLOB(2M));

How the DerbyRulebaseResolver works

When an instance of the Oracle Determinations Interview Engine is created, it first loads one of the default RulebaseResolverPlugins. When the plugin resolver discovers a custom RulebaseResolverPlugin (that is, DerbyRulebaseResolver) is available, it uses this to replace the default Rulebase Resolver.

When the initialize method is called, DerbyRulebaseResolver plugin queries the table to retrieve a list of all the rulebases and modules that exist in the database, adds them to a change set and pushes them into the RulebaseService via the applyChangeSet(…) method. The Rulebase Service then loads all the rulebases in the change set ready to be used.

The getInstance method implementation tests that the database is available before returning an initialized instance of the plugin.

Source Code

To view the source code for the RulebaseResolver sample, refer to examples\interview-engine\rulebase-resolver in the Java runtime zip file.

 

See also:

Load rulebases and rule modules in the Determinations Engine